package com.jetbrains.kmpapp

import android.content.Context
import android.content.pm.ApplicationInfo
import android.os.Build
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

private class PlatformConfigurationProvider : KoinComponent {
    private val context: Context by inject()

    // 直接在这里通过 Context 判断 isDebug 状态
    val isDebug: Boolean
        get() = (context.applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0

    val appName: String
        get() = context.applicationInfo.loadLabel(context.packageManager).toString()

    val appVersion: String
        get() = context.packageManager.getPackageInfo(context.packageName, 0).versionName
            ?: "Unknown"

    val packageName: String
        get() = context.packageName

    val platformName: String
        get() = "Android ${Build.VERSION.RELEASE}"

    val deviceModel: String
        get() = "${Build.MANUFACTURER} ${Build.MODEL}"

}

actual val platformConfiguration: PlatformConfiguration by lazy {
    val provider = PlatformConfigurationProvider()
    PlatformConfiguration(
        isDebug = provider.isDebug,
        appName = provider.appName,
        appVersion = provider.appVersion,
        packageName = provider.platformName,
        platformName = provider.platformName,
        deviceModel = provider.deviceModel
    )
}